﻿@{
}
<section class="container-fluid m15_t">
    <div class="data-wrap case">
        <form class="form-inline" id="formSearch">
            <div class="data-tool clearfix">
                <div class="pull-left form-inline ">
                    <div class="input-group input-group-sm">
                        <a class="btn btn-default btn-sm export m10_l" href="javascript:void(0)" data-title="导出">导出</a>
                    </div>
                </div>
                <div class="pull-right">
                    <div class="input-group input-group-sm">
                        <input id="d421" class="Wdate wd175" name="startTime" type="text" value="@(ViewBag.StartTime)" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" autocomplete="off" />
                        -
                        <input id="d422" class="Wdate wd175 m5_l" name="endTime" type="text" value="@(ViewBag.EndTime)" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'d421\')}'})" autocomplete="off" />
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">状态：</label>
                        <select class="form-control gettext" name="status">
                            <option value="">请选择</option>
                            <option value="0">未打款</option>
                            <option value="1">处理中</option>
                            <option value="2">已打款</option>
                            <option value="3">驳回</option>
                        </select>
                    </div>

                    <button type="button" class="btn btn-default btn-sm active gettext" id="btnSearch">搜索</button>
                </div>
            </div>
        </form>
        <div class="data-easyui data-scroll">
            <div class="data-view">
                <div class="data-div-view table-responsive">
                    <table class="table" id="pager"></table>
                </div>
            </div>
        </div>
    </div>
</section>
@section footerScript{
    <script type="text/javascript">

        var pageSize = 10;

        $(function () {
            FlashPay.UI.DataAutoHeight();

            doSearch();

            $("#btnSearch").click(function () {
                doSearch();
            });

        });

        function Tip_success(word) {
            FlashPay.UI.Tip_success(word);
        }

        function getParams() {
            var params = $("#formSearch").serializeJSON();
            return params;
        }

        function doSearch() {
            var frozenColumns = [[
                {
                    field: 'bankName', title: "银行名称", width: 75,
                    align: 'left',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '{0}'.format(val);
                        }
                    }
                },
                {
                    field: 'cardName', title: "姓名", width: 75,
                    align: 'left',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '{0}'.format(val);
                        }
                    }
                },
                {
                    field: 'cardNumber', title: "卡号", width: 150,
                    align: 'left',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '{0}'.format(val);
                        }
                    }
                }
            ]];

            var columns = [[
                {
                    field: '_Amount',
                    title: '结算金额',
                    width: 120,
                    align: 'right'
                },
                {
                    field: '_Fee',
                    title: '手续费',
                    width: 120,
                    align: 'right'
                },
                {
                    field: '_HandTime',
                    title: '处理时间',
                    width: 120,
                    align: 'left'
                },
                {
                    field: 'status',
                    title: '状态',
                    width: 75,
                    align: 'left',
                    formatter: function (val, item) {

                        var result = "";

                        if (val == 0) {
                            result = '<span class="bold">等待审核</span>';
                        } else if (val == 1) {
                            result = '<span class="red bold">处理中</span>';
                        } else if (val == 2) {
                            result = '<span class="green bold">已打款</span>';
                        } else if (val == 3) {
                            result = '<span class="red bold">驳回</span>';
                        }

                        return result;

                    }
                },
                {
                    field: 'remark',
                    title: '备注',
                    width: 200,
                    align: 'left'
                },
                {
                    field: '_CreatedBy',
                    title: '创建人',
                    width: 120,
                    align: 'left'
                },
                {
                    field: '_CreatedDate',
                    title: '创建时间',
                    width: 120,
                    align: 'left'
                }

            ]];

            $("#pager").datagrid({
                fit: false,
                loadMsg: '数据加载中，请稍后……',
                method: "get",
                border: true,
                url: '/Business/SettleQuery',
                queryParams: getParams(),
                pagination: true,
                pageSize: pageSize,
                pageList: [10, 15, 30, 50, 100, 1000],
                height: $(window).height() - 70,
                singleSelect: true,
                rownumbers: true,
                //showFooter: true,
                idField: 'id',
                onLoadSuccess: function () {
                    pageSize = $('#pager').datagrid('options').pageSize;
                },
                frozenColumns: frozenColumns,
                columns: columns
            });
        }


        $(".export").click(function () {
            FlashPay.UI.Confirm({
                content: "下载结算订单记录需要花费大量时间,确认要下载吗？",
                ok: function () {

                    var cover = FlashPay.UI.Mask({
                        obj: $("body"),
                        opacity: 0.5
                    });

                    var query = $("#formSearch").serializeJSON();


                    FlashPay.Util.Ajax({
                        url: '/Business/SettleExport',
                        type: 'POST',
                        data: { query: query },
                        success: function (response) {
                            if (response.success) {
                                cover.Remove();
                                if (response.rows != null && response.rows.length > 0) {
                                    var body = '<table>';

                                    body += '<tr>';
                                    body += '<td>银行名称</td>';
                                    body += '<td>姓名</td>';
                                    body += '<td>卡号</td>';
                                    body += '<td>结算金额</td>';
                                    body += '<td>手续费</td>';
                                    body += '<td>处理时间</td>';
                                    body += '<td>状态</td>';
                                    body += '<td>备注</td>';
                                    body += '<td>创建人</td>';
                                    body += '<td>创建时间</td>';
                                    body += '</tr>';


                                    $.each(response.rows, function (i, item) {

                                        var _status = '';
                                        var status = [
                                            { value: 0, Text: '<span class="bold">等待审核</span>' },
                                            { value: 1, Text: '<span class="red bold">处理中</span>' },
                                            { value: 2, Text: '<span class="green bold">已打款</span>' },
                                            { value: 3, Text: '<span class="red bold">驳回</span>' },
                                        ];

                                        var statusFindResult = status.find(x => { return x.value === item.status; });
                                        if (statusFindResult) {
                                            _status += statusFindResult.Text;
                                        }


                                        body += '<tr>';
                                        body += '<td>' + item.bankName + '</td>';
                                        body += '<td>' + item.cardName + '</td>';
                                        body += '<td>' + item.cardNumber + '</td>';
                                        body += '<td>' + item._Amount + '</td>';
                                        body += '<td>' + item._Fee + '</td>';
                                        body += '<td>' + item._HandTime + '</td>';
                                        body += '<td>' + _status + '</td>';
                                        body += '<td>' + item.remark + '</td>';
                                        body += '<td>' + item._CreatedBy + '</td>';
                                        body += '<td>' + item._CreatedDate + '</td>';
                                        body += '</tr>';
                                    });

                                    body += '</table>';

                                    var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
                                    excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
                                    excelFile += "<head>";
                                    excelFile += "<!--[if gte mso 9]>";
                                    excelFile += "<xml>";
                                    excelFile += "<x:ExcelWorkbook>";
                                    excelFile += "<x:ExcelWorksheets>";
                                    excelFile += "<x:ExcelWorksheet>";
                                    excelFile += "<x:Name>";
                                    excelFile += "Sheet1";
                                    excelFile += "</x:Name>";
                                    excelFile += "<x:WorksheetOptions>";
                                    excelFile += "<x:DisplayGridlines/>";
                                    excelFile += "</x:WorksheetOptions>";
                                    excelFile += "</x:ExcelWorksheet>";
                                    excelFile += "</x:ExcelWorksheets>";
                                    excelFile += "</x:ExcelWorkbook>";
                                    excelFile += "</xml>";
                                    excelFile += "<![endif]-->";
                                    excelFile += "</head>";
                                    excelFile += "<body>";
                                    excelFile += body;
                                    excelFile += "</body>";
                                    excelFile += "</html>";

                                    var uri = window.URL.createObjectURL(new Blob([excelFile], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }));
                                    var link = document.createElement("a");
                                    link.href = uri;

                                    link.style = "visibility:hidden";
                                    link.download = response.statusCode + ".xls";

                                    document.body.appendChild(link);
                                    link.click();
                                    document.body.removeChild(link);
                                }
                                else {
                                    cover.Remove();
                                    FlashPay.UI.Tip_short_warning("暂无记录");
                                }

                            } else {
                                cover.Remove();
                                FlashPay.UI.Tip_short_warning("操作失败！" + response.errorMessage);
                            }
                        },
                        error: function (json) {
                            cover.Remove();
                            FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                        }
                    });
                }
            });
        })

    </script>
}